from typing import List


class Solution:
    def minSum(self, nums1: List[int], nums2: List[int]) -> int:
        total1, total2 = 0, 0
        n_zero1, n_zero2 = 0, 0
        for num in nums1:
            if num:
                total1 += num
            else:
                n_zero1 += 1
        for num in nums2:
            if num:
                total2 += num
            else:
                n_zero2 += 1
        if not n_zero1:
            if total2 + n_zero2 > total1:
                return -1
        if not n_zero2:
            if total1 + n_zero1 > total2:
                return -1
        return max(total1 + n_zero1, total2 + n_zero2)

